//
//  UIButton+Extension.swift
//  sanwuWeibo
//
//  Created by 王先强 on 15/12/6.
//  Copyright © 2015年 王先强. All rights reserved.
//

import UIKit

extension UIButton {
    convenience init(imageName: String, backgrondImageName: String) {
        
        self.init()
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        setBackgroundImage(UIImage(named: backgrondImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backgrondImageName + "_highlighted"), forState: UIControlState.Highlighted)
        sizeToFit()
        
    }
    
    convenience init(imageName: String) {
        self.init()
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        sizeToFit()
        
    }
    
    func changeButtonImage(imageName: String){
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)

    }
    
    convenience init(backgroundImageName: String, title: String, color: UIColor) {
        self.init()
        setBackgroundImage(UIImage(named: backgroundImageName), forState: UIControlState.Normal)
        setTitle(title, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(15)
        setTitleColor(color, forState: UIControlState.Normal)
  
    }
    convenience init(imageName: String, title: String, fontSize: CGFloat, color: UIColor) {
        self.init()
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setTitle(title, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(color, forState: UIControlState.Normal)
        sizeToFit()
    }
    convenience init(title: String, bgroundColor: UIColor,fgroundColor: UIColor,fontSize: CGFloat) {
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(fgroundColor, forState: UIControlState.Normal)
        backgroundColor = bgroundColor
        sizeToFit()
    }
}
